package hyl.base.net.iot;

import java.io.Serializable;
import hyl.core.data.ExBlockMap;
import hyl.core.data.Bytes;
import hyl.core.net.IReader;
/**
 * B类节点在上级服务器中的缓冲区
 * 
 * 要先open 才可以 get()
 * 
 * 
 * @author 37798955@qq.com
 *
 */
public class InfoMap implements Serializable {

	private static final long serialVersionUID = 1L;
	/**
	 * 编号
	 */
	Integer id;
	/**
	 * 读取器A-B
	 */

	IReader reader;

	/**
	 * 附加属性， 多个终端共用一个B服务站点,
	 * 
	 * attach保存 每个c端的历史会话状态 ，
	 * 
	 * 如果重启 ，自动释放<br>
	 * 
	 * key == 路径+指令 
	 * 
	 * value == 最新应答 ==c应答的消息
	 */
	ExBlockMap<Bytes, Netpg3> attach;
	public InfoMap() {
	}

	public InfoMap(int bid, IReader reader) {
		
		setId( bid);
		this.reader = reader;
	}
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
		attach = new ExBlockMap<>(3000);
	}
	public boolean isBlock(Bytes cid_cmd) {
		return attach.hasReply(cid_cmd);
	}
	/**
	 * 要先open 才可以使用 键
	 * @param id_cmd
	 */
	public void openReply(Bytes id_cmd) {
		attach.open(id_cmd);
	}
	public void setReply(Bytes id_cmd,Netpg3 value) {
		attach.put(id_cmd, value);
	}

	public Netpg3 getReply(Bytes cid_cmd) {
		return attach.get(cid_cmd);
	}

	public void delReply(Bytes cid_cmd) {
		attach.close(cid_cmd);
	}



}
